home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7105 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1023 b   |  47 lines

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: meaning of int a::*b
  5. Date: 20 Feb 1996 18:13:58 GMT
  6. Organization: Borland International
  7. Message-ID: <4gd316$f3p@druid.borland.com>
  8. References: <31284007.7977@mercury.co.il>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <31284007.7977@mercury.co.il>, wygodny@mercury.co.il says...
  15. >
  16. >In the following (compilable) program:
  17. >
  18. >class a{};
  19. >int a::*b;
  20. >void main(){}
  21. >
  22. >Does someone know what is the meaning of int a::*b; ?
  23. >It's probably a declaration of a variable b of type int a::* . 
  24. >But what
  25. >does it mean? What can be assigned to it?
  26.  
  27. It's a pointer to a member of a of type int. You can assign it the address of 
  28. a member of a of type int:
  29.  
  30. class A
  31. {
  32. public:
  33.     int i;
  34.     int j;
  35. };
  36.  
  37. int main()
  38. {
  39.     A a;
  40.     int A::*aptr = &A::i;
  41.     a.*aptr = 3;    // assign 3 to a.i
  42.     aptr = &A::j;
  43.     a.*aptr = 4;    // assign 4 to a.j
  44.     return 0;
  45. }
  46.  
  47.